import {useCallback, useState} from 'react'
import type {PaginationProps} from '@arco-design/web-react'

export function usePagination(defaultPageSize = 20) {
  const [pageNum, setPageNum] = useState(1)
  const [pageSize, setPageSize] = useState(defaultPageSize)
  const [total, setTotal] = useState(0)
  const sizeOptions = [20, 50, 100]
  const pagination: PaginationProps = {
    current: pageNum,
    pageSize: pageSize,
    sizeOptions: sizeOptions,
    total: total,
    sizeCanChange: true,
    onChange: (page: number, size: number) => {
      setPageNum(page)
      setPageSize(size)
    },
  }
  const resetPage = useCallback(() => {
    setPageNum(1)
    setPageSize(defaultPageSize)
  }, [defaultPageSize])

  return {
    pageNum,
    pageSize,
    pagination,
    setTotal,
    resetPage,
  }
}
